<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Customer_service extends MX_Controller {
    
  function __construct() {      
    
    $this->load->library('template');
    $this->load->library('form_eksternal');
    $this->load->library('global_models');
    $this->load->library('PHPExcel');
    $this->load->library('encrypt');
    $this->load->helper('path');
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('parser');
    $this->load->library('session');
    $this->load->library('form_validation');
    $this->load->library('pagination');
    $this->menu = $this->cek();
  }
  
  public function addrow_log_pica(){
    print "
      <tr id='log_pica_{$this->input->post("no")}'>
      <td>
      {$this->form_eksternal->form_textarea("log_note[]")}
      </td>";
    print "<td valign='top'>
      {$this->form_eksternal->form_date("log_date[]", "", "log_date_{$this->input->post("no")}")}
      </td>";
    print <<<EOD
      <td><a href='javascript:void(0)' class='remove-element' onclick='del_row_lokal("log_pica_{$this->input->post("no")}")' title='Remove' >Remove</a></td>
    </tr>
EOD;
    die;
  }

  public function add_pica($id_history = 0){
    $data = $this->global_models->get("d_history", array("id_history" => $id_history));
    if($this->input->post()){
      $pst = $this->input->post();
      if($pst['id_detail']){
        $kirim = array(
            "id_pic_users"            => $this->session->userdata("id"),
            "id_actifity_report"      => $pst['id_actifity_report'],
            "id_outlet"               => $pst['id_outlet'],
            "problem"                 => $pst['problem'],
            "corrective"              => $pst['corrective'],
            "due_date"                => $pst['due_date'],
            "kategori"                => $pst['kategori'],
            "fix"                     => $pst['fix'],
            "id_kategori_pica"        => $pst['id_kategori_pica'],
            "sumber_info_view"        => $pst['sumber_info_view'],
            "tanggal_buat"            => $pst['tanggal_buat'],
            "id_pic_pica"             => $pst['id_pic_pica'],
            "panggilan"               => $pst['panggilan'],
            "nama_pelapor"            => $pst['nama_pelapor'],
            "email_pelapor"           => $pst['email_pelapor'],
            "telp_pelapor"            => $pst['telp_pelapor'],
            "tanggal_mulai"           => $pst['tanggal_mulai'],
            "inisial_respons"         => $pst['inisial_respons'],
            "no_tiket"                => $pst['code_tiket']."-".date("dmY", strtotime($pst['tanggal_tiket']))."-".str_pad($pst['no_tiket'], 4, '0', STR_PAD_LEFT),
            "no_seri"                 => $pst['no_tiket'],
            "bulan_seri"              => date("m", strtotime($pst['tanggal_tiket'])),
            "update_by_users"         => $this->session->userdata("id"),
        );
        if($pst['fix'] == 2 AND $data[0]->fix != 2){
          $kirim['tanggal_selesai']   = date("Y-m-d");
        }
        $id_history = $this->global_models->update("d_history", array("id_history" => $pst['id_detail']), $kirim);
        $id_history_real = $pst['id_detail'];
      }
      else{
        $kirim = array(
            "id_pic_users"            => $this->session->userdata("id"),
            "id_actifity_report"      => $pst['id_actifity_report'],
            "id_outlet"               => $pst['id_outlet'],
            "problem"                 => $pst['problem'],
            "corrective"              => $pst['corrective'],
            "due_date"                => $pst['due_date'],
            "kategori"                => $pst['kategori'],
            "fix"                     => $pst['fix'],
            "id_kategori_pica"        => $pst['id_kategori_pica'],
            "sumber_info_view"        => $pst['sumber_info_view'],
            "tanggal_buat"            => $pst['tanggal_buat'],
            "id_pic_pica"             => $pst['id_pic_pica'],
            "panggilan"               => $pst['panggilan'],
            "nama_pelapor"            => $pst['nama_pelapor'],
            "email_pelapor"           => $pst['email_pelapor'],
            "telp_pelapor"            => $pst['telp_pelapor'],
            "tanggal_mulai"           => $pst['tanggal_mulai'],
            "inisial_respons"         => $pst['inisial_respons'],
            "no_tiket"                => $pst['code_tiket']."-".date("dmY", strtotime($pst['tanggal_tiket']))."-".str_pad($pst['no_tiket'], 4, '0', STR_PAD_LEFT),
            "no_seri"                 => $pst['no_tiket'],
            "bulan_seri"              => date("m", strtotime($pst['tanggal_tiket'])),
            "create_by_users"         => $this->session->userdata("id"),
            "create_date"             => date("Y-m-d H:i:s")
        );
        $id_history = $this->global_models->insert("d_history", $kirim);
        $id_history_real = $id_history;
      }
      if($id_history){
        foreach($pst['log_note'] AS $kln => $log_note){
          if($log_note){
            $kirim_log[] = array(
                "id_history"              => $id_history_real,
                "tanggal"                 => $pst['log_date'][$kln],
                "note"                    => $log_note,
                "create_by_users"         => $this->session->userdata("id"),
                "create_date"             => date("Y-m-d H:i:s")
            );
          }
        }
        if($kirim_log){
          $this->global_models->insert_batch("d_history_log", $kirim_log);
        }
        $this->session->set_flashdata('success', 'Data tersimpan');
      }
      else{
        $this->session->set_flashdata('notice', 'Data tidak tersimpan');
      }
      redirect("outlet/pica-all/");
    }
    else{
      
      
      $data_log = $this->global_models->get("d_history_log", array("id_history" => $id_history));
      $no = 1;
      if($data_log){
        foreach($data_log AS $dl){
          $isi[$no] = array(
              nl2br($dl->note)."<hr />",
              $dl->tanggal
          );
          $tr[$no] = "tr_{$no}";
          $no++;
        }
      }
      else{
        $isi[1] = array(
          $this->form_eksternal->form_textarea("log_note[]"),
          $this->form_eksternal->form_date("log_date[]", "", "log_date_1")
        );
        $tr[1] = "tr_1";
      }
    
      $this->template->build("add-pica",
        array(
              'url'     => base_url()."themes/srabon/",
              'menu'        => 'outlet/milik',
              'title'       => "Add PICA",
              'detail'      => $data,
              'isi'         => $isi,
              'tr'          => $tr,
            ));
      $this->template
        ->set_layout('default')
        ->build("add-pica");
    }
	}
  
  function master_kategori_pica(){
    $list = $this->global_models->get("m_kategori_pica");
//    $this->debug($list, true);
    $this->template->title('Sistem', "Outlet");
    $view = "master-kategori-pica";
    $this->template->build($view, 
      array('message' => "",
            'url'     => base_url()."themes/srabon/",
            'data'    => $list,
            'menu_drop'   => $this->menu,
            'menu'        => "settings",
            'title_table'    => "Kategori PICA",
            'foot'    => ""
          ));
    $this->template
      ->set_layout('default')
      ->build($view);
  }
  
  function add_kategori_pica($id_kategori_pica = 0){
    if($this->input->post()){
      $pst = $this->input->post();
      if($pst['id_detail']){
        $kirim = array(
            "name"            => $pst['name'],
            "kategori"        => $pst['kategori'],
            "update_by_users" => $this->session->userdata("id"),
        );
        $id_kategori_pica = $this->global_models->update("m_kategori_pica", array("id_kategori_pica" => $pst['id_detail']), $kirim);
      }
      else{
        $kirim = array(
            "name"            => $pst['name'],
            "kategori"        => $pst['kategori'],
            "create_by_users" => $this->session->userdata("id"),
            "create_date"     => date("Y-m-d H:i:s")
        );
        $id_kategori_pica = $this->global_models->insert("m_kategori_pica", $kirim);
      }
      if($id_kategori_pica){
        $this->session->set_flashdata('success', 'Data tersimpan');
      }
      else{
        $this->session->set_flashdata('notice', 'Data tidak tersimpan');
      }
      redirect("customer-service/master-kategori-pica");
    }
    else{
      $data = $this->global_models->get("m_kategori_pica", array("id_kategori_pica" => $id_kategori_pica));
      $view = "add-kategori-pica";
      $this->template->build($view, 
        array('message' => "",
              'url'     => base_url()."themes/srabon/",
              'data'    => $data,
              'menu_drop'   => $this->menu,
              'menu'        => "settings",
              'title'    => "Kategori PICA",
            ));
      $this->template
        ->set_layout('default')
        ->build($view);
    }
  }
  
  function get_dropdown_kategori($id_topic){
    $kategori_class = $this->global_models->get_dropdown("m_kategori_pica", "id_kategori_pica", "name", FALSE, array("kategori" => $id_topic));
    print $this->form_eksternal->form_dropdown('id_kategori_pica', $kategori_class, "");die;
  }
  
  function rekap_bulan_create(){
//    $awal_bulan = date("Y-").'06-01';
    $awal_bulan = date("Y-m-").'01';
    $sekarang = date("Y-m-d");
    $data_create = $this->global_models->get_query("
      SELECT A.*, B.name AS outlet, C.name AS pic
      FROM d_history AS A
      LEFT JOIN m_outlet AS B ON A.id_outlet = B.id_outlet
      LEFT JOIN m_pic_pica AS C ON A.id_pic_pica = C.id_pic_pica
      WHERE (A.tanggal_buat BETWEEN '{$awal_bulan}' AND '{$sekarang}')
        AND A.fix = 1
        ORDER BY A.tanggal_buat DESC
      ");
      
    $this->template->build('rekap-bulan-ini', 
      array(
            'message'     => "",
            'url'     => base_url()."themes/srabon/",
            'menu_drop'   => $this->menu,
            'menu'        => "outlet",
            'title_table'    => "Rekap PICA Progress Bulan ".date("F"),
            'data' => $data_create,
            'berdasarkan' => "Create Date",
            'tanggal_inisialisasi' => "tanggal_buat",
            'boxy'        => "data-tbl-boxy4",
          ));
    $this->template
      ->set_layout('default')
      ->build('rekap-bulan-ini');
  }
  
  function rekap_bulan_due_date(){
//    $awal_bulan = date("Y-").'06-01';
    $awal_bulan = date("Y-m-").'01';
    $sekarang = date("Y-m-d");
    
    $data_due_date = $this->global_models->get_query("
      SELECT A.*, B.name AS outlet, C.name AS pic
      FROM d_history AS A
      LEFT JOIN m_outlet AS B ON A.id_outlet = B.id_outlet
      LEFT JOIN m_pic_pica AS C ON A.id_pic_pica = C.id_pic_pica
      WHERE (A.due_date BETWEEN '{$awal_bulan}' AND '{$sekarang}')
        AND A.fix = 1
        ORDER BY A.tanggal_buat DESC
      ");
      
    $this->template->build('rekap-bulan-ini', 
      array(
            'message'     => "",
            'url'     => base_url()."themes/srabon/",
            'menu_drop'   => $this->menu,
            'menu'        => "outlet",
            'title_table'    => "Rekap PICA Due Date Bulan ".date("F"),
            'data' => $data_due_date,
            'berdasarkan' => "Due Date",
            'tanggal_inisialisasi' => "due_date",
            'boxy'        => "data-tbl-boxy",
          ));
    $this->template
      ->set_layout('default')
      ->build('rekap-bulan-ini');
  }
  
  function rekap_bulan_finish(){
//    $awal_bulan = date("Y-").'06-01';
    $awal_bulan = date("Y-m-").'01';
    $sekarang = date("Y-m-d");
    
    $data_fix = $this->global_models->get_query("
      SELECT A.*, B.name AS outlet, C.name AS pic
      FROM d_history AS A
      LEFT JOIN m_outlet AS B ON A.id_outlet = B.id_outlet
      LEFT JOIN m_pic_pica AS C ON A.id_pic_pica = C.id_pic_pica
      WHERE (A.tanggal_selesai BETWEEN '{$awal_bulan}' AND '{$sekarang}')
        AND A.fix = 2
        ORDER BY A.tanggal_buat DESC
      ");
     
    $this->template->build('rekap-bulan-ini', 
      array(
            'message'     => "",
            'url'     => base_url()."themes/srabon/",
            'menu_drop'   => $this->menu,
            'menu'        => "outlet",
            'title_table'    => "Rekap PICA Close Bulan ".date("F"),
            'data' => $data_fix,
            'berdasarkan' => "Finish Date",
            'tanggal_inisialisasi' => "tanggal_selesai",
            'boxy'        => "data-tbl-boxy4",
          ));
    $this->template
      ->set_layout('default')
      ->build('rekap-bulan-ini');
  }
  
  function report_pica(){
    
    $id_outlet = $this->global_models->get_field("d_outlet_users", "id_outlet", array("id_users" => $this->session->userdata("id")));
    $this->session->set_userdata(array("pica_search_outlet" => $id_outlet));
    
    if($this->input->post("report", TRUE)){
      $this->moutlet->pica_report_xls();
    }
    if($this->input->post("rekap", TRUE)){
      $this->moutlet->pica_rekap_xls();
    }
       
  //echo $this->session->userdata("id_privilege"); exit;
        $parent = array(
        1 => "SDM",
        2 => "Service",
        3 => "Administrasi",
        4 => "Promo",
        5 => "Tools",
        6 => "IT - Software & Hardware",
        7 => "Parts",
        9 => "Lainnya"
    );
        
        $status = array(
            "all" => "All",
            0 => "Draft",
            1 => "Progress",
            2 => "Finish",
        );
        
        $berdasar = array(
            "tanggal_buat"      => "Report Date",
            "due_date"          => "Due Date",
            "tanggal_selesai"   => "Finish Date",
        );
       
       //  $dropdown = array();
        $dropdown = array_reverse($parent, true);
   // $this->template->title('Sistem', "Outlet");
       $pr = $this->nbscache->get_explode("pica_permission", $this->session->userdata("id_privilege"));
       $pica_ca = unserialize($pr[1]);

       if($this->session->userdata("id_privilege") > 0){
       $parent = array_intersect($parent, $pica_ca);
      
       $dropdown = array_intersect($dropdown, $pica_ca);
       }else{
           $dropdown = $dropdown;
       }
         
      if(is_array($dropdown)){
      foreach ($dropdown as $key => $value) {
        $dropdown[$key] = $value;
      }
    }
    $dropdown[0] = "-- Pilih --";
   $dropdown = array_reverse($dropdown, true);
   
//   $status[0] = "-- Pilih --";
//  $status =   array_reverse($status, true);
    // $dropdown =  array_merge($dropdown, $parent);
   
    if($this->input->post() AND !$this->input->post("export", TRUE)){
      
//   if($this->input->post("export", TRUE)){
//       $session_xls = array(
//            "pica_search_export1"        => $this->input->post("export"),
//           "pica_search_outlet1"        => $this->input->post("outlet"),
//            "pica_search_id_kategori1"         => $this->input->post("id_kategori"),
//            "pica_search_id_fix1"       => $this->input->post("id_fix"),
//            "pica_search_bc_name1"   => $this->input->post("bc_name"),
//            "pica_search_start_date1"  => $this->input->post("start_date"),
//            "pica_search_end_date1"     => $this->input->post("end_date"),
//        );
//       $this->session->set_userdata($session_xls);
//       
//     $session_cari = array(
//            "pica_search_outlet"        => "",
//            "pica_search_id_kategori"         => "",
//            "pica_search_id_fix"   => "",
//            "pica_search_bc_name"  => "",
//            "pica_search_start_date"     => "",
//            "pica_search_end_date"    => "",
//        );
//        $this->session->unset_userdata($session_cari);
//      }
      if($this->input->post('cari') == 's'){
        $session_cari = array(
            "pica_search_outlet"              => $this->input->post("id_outlet"),
            "pica_search_id_kategori"         => $this->input->post("id_kategori"),
            "pica_search_id_fix"              => $this->input->post("id_fix"),
            "pica_search_start_date"          => $this->input->post("start_date"),
            "pica_search_end_date"            => $this->input->post("end_date"),
            "pica_search_date_berdasar"       => $this->input->post("date_berdasar"),
            "pica_sort"                       => $this->input->post("sort"),
        );
        $this->session->set_userdata($session_cari);
        redirect("customer-service/report-pica");
      }
      else{
        $session_cari = array(
            "pica_search_outlet"        => "",
            "pica_search_id_kategori"         => "",
            "pica_search_id_fix"   => "1",
            "pica_search_bc_name"  => "",
            "pica_search_start_date"     => "",
            "pica_search_end_date"    => "",
            "pica_search_date_berdasar"       => "tanggal_buat",
            "pica_sort"                       => "A.due_date ASC",
        );
        $this->session->set_userdata($session_cari);
        redirect("customer-service/report-pica");
      }
     
      
    }
   
 
//    foreach ($parent as $ky => $prt){
    
    if(!$this->session->userdata("pica_search_id_fix"))
      $this->session->set_userdata(array("pica_search_id_fix" => 1));
        
      if($this->session->userdata("pica_search_outlet")){
        $where .= " AND A.id_outlet = {$this->session->userdata("pica_search_outlet")} ";
      }

      if($this->session->userdata("pica_search_id_kategori")){
        $where .= " AND A.kategori = {$this->session->userdata("pica_search_id_kategori")} ";
      }

      if($this->session->userdata("pica_search_id_fix") != "" AND $this->session->userdata("pica_search_id_fix") != "all"){
        $where .= " AND A.fix = {$this->session->userdata("pica_search_id_fix")} ";
      }

      if($this->session->userdata("pica_search_start_date")){
        $where .= " AND (A.{$this->session->userdata("pica_search_date_berdasar")} BETWEEN '{$this->session->userdata("pica_search_start_date")}' AND '{$this->session->userdata("pica_search_end_date")}') ";
      }
    
      $data = $this->global_models->get_query("
      SELECT count(id_history) AS jumlah FROM d_history AS A WHERE 1=1 {$where}
         ORDER BY  `A`.`create_date` ASC
      "); 
      
//    $data_export[$ky] = $this->global_models->get_query("
//        SELECT A . * , B.name AS laporan, C.name AS name_outlet FROM d_history AS A
//        LEFT JOIN m_actifity_report AS B ON A.id_actifity_report = B.id_actifity_report
//        LEFT JOIN m_outlet AS C ON B.id_outlet = C.id_outlet
//		$data_join
//        LEFT JOIN d_pic_users as D on A.id_pic_users = D.id_pic_users
//        LEFT JOIN m_users as E on D.id_users = E.id_users
//        LEFT JOIN d_user_privilege F ON F.id_users = E.id_users
//       where  $queryData $queryWhere $query2 $query $query1
//       ORDER BY  `A`.`create_date` ASC 
//      "); 
//     
//      }
      if($this->input->post("export", TRUE)){
        if($this->session->userdata("pica_sort")){
      $sorting = $this->session->userdata("pica_sort");
    }
    else{
      $sorting = "A.due_date ASC";
    }
    
    if($this->session->userdata("pica_search_outlet")){
      $where_eks .= " AND A.id_outlet = {$this->session->userdata("pica_search_outlet")} ";
    }
    
    if($this->session->userdata("pica_search_id_kategori")){
      $where_eks .= " AND A.kategori = {$this->session->userdata("pica_search_id_kategori")} ";
    }
    
    if($this->session->userdata("pica_search_id_fix") != "" AND $this->session->userdata("pica_search_id_fix") != "all"){
      $where_eks .= " AND A.fix = {$this->session->userdata("pica_search_id_fix")} ";
    }
    
    if($this->session->userdata("pica_search_start_date")){
      $where_eks .= " AND (A.{$this->session->userdata("pica_search_date_berdasar")} BETWEEN '{$this->session->userdata("pica_search_start_date")}' AND '{$this->session->userdata("pica_search_end_date")}') ";
    }
    
        $data_export = $this->global_models->get_query("
         SELECT A.*, B.name as outlet, C.name AS pic, D.name AS kategori_pica
         FROM d_history AS A
         LEFT JOIN m_outlet AS B ON A.id_outlet = B.id_outlet
         LEFT JOIN m_pic_pica AS C ON A.id_pic_pica = C.id_pic_pica
         LEFT JOIN m_kategori_pica AS D ON A.id_kategori_pica = D.id_kategori_pica
         WHERE 1=1 {$where_eks}
         ");
    
//        $this->debug($data_export, true);
     // echo $this->session->userdata('pica_search_export1'); echo $this->session->userdata('pica_search_id_kategori1'); die;
        $this->moutlet->pica_all_xls($parent,$data_export);
        
      }
    if(!$this->input->post(NULL, TRUE)){
      $this->template->build('pica-all', 
        array(
              'message'     => "",
              'url'     => base_url()."themes/srabon/",
              'menu_drop'   => $this->menu,
              'menu'        => "outlet",
              'detail'        => $detail,
              'data_total'        => $data,
               'pagerow'  => $pages,
              'parent'        => $parent,
            'fix'   => $status,
            'dropdown'        => $dropdown,
              'title_table'    => "PICA All Outlet",
            'search_table'    => "Search PICA",
            'berdasar'    => $berdasar,
              'foot'    => ""
            ));
      $this->template
        ->set_layout('default')
        ->build('pica-all');
    } 
  }
  
  public function ajax_pica_all($total = 0, $start = 0){
    
    
//    $session_cari = array(
//        "pica_search_outlet"              => $this->input->post("outlet"),
//        "pica_search_id_kategori"         => $this->input->post("id_kategori"),
//        "pica_search_id_fix"              => $this->input->post("id_fix"),
//        "pica_search_start_date"          => $this->input->post("start_date"),
//        "pica_search_end_date"            => $this->input->post("end_date"),
//        "pica_sort"                       => $this->input->post("sort"),
//    );
    if($this->session->userdata("pica_sort")){
      $sorting = $this->session->userdata("pica_sort");
    }
    else{
      $sorting = "A.due_date ASC";
    }
    
    if($this->session->userdata("pica_search_outlet")){
      $where .= " AND A.id_outlet = {$this->session->userdata("pica_search_outlet")} ";
    }
    
    if($this->session->userdata("pica_search_id_kategori")){
      $where .= " AND A.kategori = {$this->session->userdata("pica_search_id_kategori")} ";
    }
    
    if($this->session->userdata("pica_search_id_fix") != "" AND $this->session->userdata("pica_search_id_fix") != "all"){
      $where .= " AND A.fix = {$this->session->userdata("pica_search_id_fix")} ";
    }
    
    if($this->session->userdata("pica_search_start_date")){
      $where .= " AND (A.{$this->session->userdata("pica_search_date_berdasar")} BETWEEN '{$this->session->userdata("pica_search_start_date")}' AND '{$this->session->userdata("pica_search_end_date")}') ";
    }
    
     $data = $this->global_models->get_query("
      SELECT A.*, B.name as outlet, C.name AS pic, D.name AS kategori_pica
      FROM d_history AS A
      LEFT JOIN m_outlet AS B ON A.id_outlet = B.id_outlet
      LEFT JOIN m_pic_pica AS C ON A.id_pic_pica = C.id_pic_pica
      LEFT JOIN m_kategori_pica AS D ON A.id_kategori_pica = D.id_kategori_pica
      WHERE 1=1 {$where}
      ORDER BY {$sorting} LIMIT {$start},10
      ");
    
    $kategori = array(
        1 => "SDM",
        2 => "Service",
        3 => "Administrasi",
        4 => "Promo",
        5 => "Tools",
        6 => "IT - Software & Hardware",
        7 => "Parts",
        9 => "Lainnya"
    );
    
    $sumber = array(
        1 => "Email",
        2 => "Telphone",
        3 => "Pesan Singkat",
    );
    $status = array(
        0 => "<span class='label'>Draft</span>",
        1 => "<span class='label label-info'>Progress</span>",
        2 => "<span class='label label-success'>Finish</span>",
    );
    $panggilan = array(
        1 => "Bapak",
        2 => "Ibu",
    );
    
    $post_fix = site_url("outlet/post-fix");
    
     
    foreach ($data as $key => $value) {
      
      $awal_time = strtotime($value->tanggal_buat);
      $selesai_time = strtotime($value->tanggal_selesai);
      $over_time = strtotime($value->due_date);
      if($value->tanggal_selesai)
        $sekarang = gregoriantojd(date("m", $selesai_time), date("d", $selesai_time), date("Y", $selesai_time));
      else
        $sekarang = gregoriantojd(date("m"), date("d"), date("Y"));

      $awal_laporan = gregoriantojd(date("m", $awal_time), date("d", $awal_time), date("Y", $awal_time));
      $lama_laporan = $sekarang - $awal_laporan;

      if($value->tanggal_selesai){
        $selesai_laporan = gregoriantojd(date("m", $selesai_time), date("d", $selesai_time), date("Y", $selesai_time));
        $lama_pengerjaan = $selesai_laporan - $awal_laporan;
        $sekarang_over = $selesai_laporan;
      }
      else{
        $lama_pengerjaan = "-";
        $sekarang_over = $sekarang;
      }

      $over_laporan = gregoriantojd(date("m", $over_time), date("d", $over_time), date("Y", $over_time));
      $lama_kelewatan =  $sekarang_over - $over_laporan;
      if($lama_kelewatan < 0){
        $cetak_over = "";
      }
      else{
        $cetak_over = "<br /> Over Due : {$lama_kelewatan} hari";
      }
      
      $benar = FALSE;
      $disable = '';
      if($value->fix == 2){
        $benar = TRUE;
        $disable = 'disabled';
      }
      
      $history_data = $this->global_models->get("d_history_log", array("id_history" => $value->id_history));
      $history = "";
      foreach($history_data as $hd){
        $history .= "
          <p><h5>{$hd->tanggal}</h5>
            ".  nl2br($hd->note)."
          </p>
          ";
      }
      
      print "
      <tr class='ajax-pica'>
        <td>
          <a href='#myModal_{$value->id_history}' data-toggle='modal'>{$value->outlet}</a>
          <div class='modal hide fade' id='myModal_{$value->id_history}'>
            <div class='modal-header'>
              <button type='button' class='close' data-dismiss='modal'>×</button>
              <h3>Log</h3>
            </div>
            <div class='modal-body'>
              {$history}
            </div>
            <div class='modal-footer'>
              <a href='#' class='btn' data-dismiss='modal'>Close</a>
            </div>
          </div>
        </td>
        <td>
          Topik : {$kategori[$value->kategori]}
          <br /> Kategori : {$value->kategori_pica}
          <br /> Sumber : {$sumber[$value->sumber_info_view]}
          <br /> Status : <span id='status_view_{$value->id_history}'>{$status[$value->fix]}</span>
          <br /> Pelapor : <b>{$panggilan[$value->panggilan]} {$value->nama_pelapor}</b>
          <br /> Email : <b>{$value->email_pelapor}</b>
          <br /> Telphone : <b>{$value->telp_pelapor}</b>
        </td>
        <td>{$value->problem}</td>
        <td>{$value->corrective}</td>
        <td>
          <span id='info_waktu_{$value->id_history}'>
            Report Date : {$value->tanggal_buat}
          <br /> Due Date : {$value->due_date}
          <br /> Finish Date : {$value->tanggal_selesai}
          <br /> Lama Laporan : {$lama_laporan} hari
          {$cetak_over}
          <br /> PIC : {$value->pic}</span>
        </td>
      </tr>
      ";
      
    }
    
    $this->load->library('pagination');

    $config['base_url'] = '';
    $config['total_rows'] = $total;
    $config['per_page'] = 10; 
    $config['uri_segment'] = 4; 
    $config['cur_tag_open'] = "<li class='active'><a href='javascript:void(0)'>"; 
    $config['cur_tag_close'] = "</a></li>"; 
    $config['first_tag_open'] = "<li>"; 
    $config['first_tag_close'] = "</li>"; 
    $config['last_tag_open'] = "<li>"; 
    $config['last_tag_close'] = "</li>"; 
    $config['next_tag_open'] = "<li>"; 
    $config['next_tag_close'] = "</li>"; 
    $config['prev_tag_open'] = "<li>"; 
    $config['prev_tag_close'] = "</li>"; 
    $config['num_tag_open'] = "<li>"; 
    $config['num_tag_close'] = "</li>";
    $config['function_js'] = "load_pica";

    $this->pagination->initialize($config); 
    print "
    <tr class='ajax-pica'>
      <td colspan='6'>
        <div class='pagination'>
          <ul>
          ".$this->pagination->create_links_ajax()."
          </ul>
        </div>
      </td>
    </tr>";
    die;
  }
  
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */